package com.changgou.order.controller;

import com.changgou.common.pojo.Result;
import com.changgou.common.pojo.StatusCode;
import com.changgou.order.pojo.OrderItem;
import com.changgou.order.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {
    /**
     * 商品添加到购物车
     */
    @Autowired
    private CartService cartService;
    @GetMapping ("/add")
    public Result add(@RequestParam  Long id, @RequestParam Integer  num){
       cartService.add(id,num,"heima");
       return  new Result(true, StatusCode.OK, "添加购物车成功");
    }
    @GetMapping("/list")
    public Result<List<OrderItem>>  list( ){
        List<OrderItem> orderItemList = cartService.list("heima");
        return  new Result<List<OrderItem>> (true, StatusCode.OK, "查询购物车成功",orderItemList);
    }
}
